from django.db import models
from dvadmin.utils.models import CoreModel

# Create your models here.

class AssetType(CoreModel):
    """资产类型表"""

    title = models.CharField(max_length=32, unique=True, verbose_name="资产类型")
    name = models.CharField(max_length=32, verbose_name="资产类型名称")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "seadmin_astype"
        verbose_name = "资产类型"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

class AssetStatus(CoreModel):
    """资产状态表"""

    title = models.CharField(max_length=32, unique=True, verbose_name="资产状态")
    name = models.CharField(max_length=32, verbose_name="资产状态名称")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "seadmin_asstatus"
        verbose_name = "资产状态"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)


class SeAssets(CoreModel):
    """资产表"""

    asid = models.CharField(max_length=32,unique=True, verbose_name="资产编号")
    asstatus = models.ForeignKey(to=AssetStatus, null=True, blank= True, default= None, on_delete=models.SET_DEFAULT, verbose_name="资产状态")
    is_ems = models.BooleanField(default=True, verbose_name="EMS列管")
    is_myfa = models.BooleanField(default=False, verbose_name="MYFA列管")
    astype = models.ForeignKey(to=AssetType,null=True, blank= True, default= None,on_delete=models.SET_DEFAULT, verbose_name="资产类型")
    asmodel = models.CharField(max_length=128,null=True, blank= True, verbose_name="资产型号")
    manufacturer = models.CharField(max_length=64,null=True, blank= True, verbose_name="资产厂商")
    assn = models.CharField(max_length=64,null=True, blank= True, verbose_name="资产序列号")

    lc_code = models.CharField(max_length=32,null=True, blank= True, verbose_name="资产位置")
    lc_rack = models.CharField(max_length=32,null=True, blank= True, verbose_name="机架位置")
    lc_dtl = models.CharField(max_length=32,null=True, blank= True, verbose_name="机架详情")
    
    order_pr = models.CharField(max_length=32, null=True, blank= True, verbose_name="订单号")
    order_item = models.CharField(max_length=32, null=True, blank= True, verbose_name="资产料号")
    order_po = models.CharField(max_length=32, null=True, blank= True, verbose_name="订单号")
    order_price = models.FloatField(null=True, blank= True, verbose_name="订单金额")
    order_dtl = models.TextField(null=True, blank= True, verbose_name="订单明细")

    admin = models.CharField(max_length=64, null=True, blank= True, verbose_name="资产管理员")
    memo = models.CharField(max_length=256, null=True, blank= True, verbose_name="备注")

    def __str__(self):
        return self.asid

    class Meta:
        db_table = "seadmin_assets"
        verbose_name = "资产总表"
        verbose_name_plural = verbose_name
        ordering = ("-update_datetime",)














